package com.shangguigu.hadoopdashujv.pojo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCountApp {
    public static void main(String[] args) throws Exception {
        //创建写入链接
        final String hdfsurl="hdfs://node1:8020";
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://node1:8020");

        Job job = Job.getInstance(conf, "Word Count");

        job.setJarByClass(WordCountApp.class);

        // 设置Mapper和Reducer类
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);

        // 设置输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        // 设置输入输出路径
        FileInputFormat.addInputPath(job, new Path("/dhd/hadoop/word.txt")); // 输入文件路径
        FileOutputFormat.setOutputPath(job, new Path("/dhd/output")); // 输出目录

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
